package com.googlecode.dgwt.client.dijit.view.render;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.TableElement;
import com.googlecode.dgwt.client.dijit.Dijit;
import com.googlecode.dgwt.client.dijit.base.widget.WidgetEngine;
import com.googlecode.dgwt.client.dijit.view.render.base.CellViewRenderBase;
import com.googlecode.dgwt.client.dijit.view.store.CellView;
import com.googlecode.dgwt.client.dojo.Dojo;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class TableRender extends CellViewRenderBase {
    
    public TableRender(CellView view) {
        super(view);
    }

    @Override
    public void doBuildRendering() {
        TableElement table = Document.get().createTableElement();
        Element tbody = Document.get().createTBodyElement();
        
        table.setBorder(0);
        table.setCellPadding(0);
        table.setCellSpacing(0);
        table.appendChild(tbody);        
        
        getEngine().setDomElement(table);
        getEngine().setAttachedElement(WidgetEngine.CONTAINER_ELEMENT, tbody);
    }

    @Override
    protected Element createRowElement() {
        return Document.get().createTRElement();
    }

    @Override
    protected Element createCellElement() {
        Element element = Document.get().createTDElement();
        if (!Dojo.navigator.isOpera()){
            Dijit.setWaiRole(element, "presentation");
        }
        return element;
    }

}
